﻿package kit4j.view.cs.swing.component;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;

import kit4j.view.cs.component.BackgroundConstraints;
import kit4j.view.cs.component.FullComponent;
import kit4j.view.cs.component.FullComponentHelper;

/**
 * 实现了FullComponent接口的继承自JButton的类型。 注意：如果该类型对象的isContentAreaFilled()方法返回值为true，则背景图设置将失效。
 * 
 * @author MiniKnife
 * 
 */
public class JFullButton extends JButton implements FullComponent {

	private static final long serialVersionUID = 1L;

	public JFullButton() {
		super();

		init();
	}

	public JFullButton(Icon icon) {
		super(icon);

		init();
	}

	public JFullButton(String text) {
		super(text);

		init();
	}

	public JFullButton(Action a) {
		super(a);

		init();
	}

	public JFullButton(String text, Icon icon) {
		super(text, icon);

		init();
	}

	private FullComponentHelper fullComponentHelper = new FullComponentHelper(this);

	private void init() {
		this.setContentAreaFilled(false);
	}

	@Override
	public void setBackgroundImage(Image img) {
		this.fullComponentHelper.setBackgroundImage(img);
	}

	@Override
	public Image getBackgroundImage() {
		return this.fullComponentHelper.getBackgroundImage();
	}

	@Override
	public void paintComponent(Graphics g) {
		this.fullComponentHelper.paintBackgroundImage(g);

		super.paintComponent(g);
	}

	@Override
	public BackgroundConstraints getBackgroundConstraints() {
		return this.fullComponentHelper.getBackgroundConstraints();
	}

	@Override
	public void setBackgroundConstraints(BackgroundConstraints bgc) {
		this.fullComponentHelper.setBackgroundConstraints(bgc);
	}

	@Override
	public void setAutoGenerateComponentsBackgroundImage(boolean autoGenerateComponentsBackgroundImage) {
		this.fullComponentHelper.setAutoGenerateComponentsBackgroundImage(autoGenerateComponentsBackgroundImage);
	}

	@Override
	public boolean isAutoGenerateComponentsBackgroundImage() {
		return this.fullComponentHelper.isAutoGenerateComponentsBackgroundImage();
	}

}
